package pri.jz.keeper.repository

import pri.jz.keeper.webservice.WebService
import pri.jz.keeper.webservice.retrofit.RegisterService

/**
 *Author by: JZ
 *Email: 2451756617@qq.com
 *PS:
 */
class RegisterRepository {
    companion object {
        const val REGISTER_SUCCESS: Int = 200 //注册成功
        const val REGISTER_REPEAT: Int = 101 //用户已存在
        const val REGISTER_FAIL: Int = 102 //注册失败
    }
    private val registerService = WebService.retrofitClient.create(RegisterService::class.java)

    /**
     * 用户注册
     * @param number
     * @param password
     * @param onUserExist 用户已存在
     * @param onRegisterSuccess 注册成功
     */
    suspend fun userRegister(
        number: String,
        password: String,
        onUserExist: () -> Unit,
        onRegisterFail: () -> Unit,
        onRegisterSuccess: () -> Unit
    ) {
        val code = registerService.userRegister(number, password)
        when (code) {
            REGISTER_SUCCESS -> onRegisterSuccess()
            REGISTER_REPEAT -> onUserExist()
            REGISTER_FAIL -> onRegisterFail()
        }
    }
}